﻿using EBA.Collections;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace EBA.Reporting.Data
{
    /// <summary>
    /// 将<see cref="DataTable"/>对象包装成<see cref="IReportDataTable"/>对象
    /// </summary>
    class AdoReportDataTable : IReportDataTable
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="dataTable">数据表</param>
        /// <param name="tableIndex">数据表索引</param>
        public AdoReportDataTable(DataTable dataTable, int tableIndex)
        {
            this.TableName = dataTable.TableName;
            this.TableIndex = tableIndex;
            this.Rows = new AdoReportDataRowCollection();
            this.Columns = new AdoReportDataColumnCollection();

            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                var row = dataTable.Rows[i];
                this.Rows.Add(new AdoReportDataRow(row, i));
            }

            for (int i = 0; i < dataTable.Columns.Count; i++)
            {
                this.Columns.Add(new AdoReportDataColumn(dataTable, i));
            }
        }

        public string TableName
        {
            get;
            set;
        }

        public int TableIndex
        {
            get;
            set;
        }

        AdoReportDataRowCollection Rows
        {
            get;
            set;
        }

        IReadonlyList<IReportDataRow> IReportDataTable.Rows
        {
            get
            {
                return this.Rows;
            }
        }

        AdoReportDataColumnCollection Columns
        {
            get;
            set;
        }

        IReadonlyList<IReportDataColumn> IReportDataTable.Columns
        {
            get
            {
                return this.Columns;
            }
        }
    }
}
